import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  mode: 'development',
  plugins: [vue()],
  //配置静态文件
  publicDir: "public",
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: '8080',
    open: true, //自动打开 
    proxy: { // 本地开发环境通过代理实现跨域
      // 正则表达式写法
      '/api': {
        target: 'http://t.weather.sojson.com/', //借用服务实际地址
        changeOrigin: true, //开启代理
        rewrite: (path) => path.replace(/^\/api/, '/api'),
      }
    }

  },
  //配置样式文件
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "./src/assets/theme.module.scss";`
      }
    }
  }
})